﻿using System.Data.Entity;
using RCSoft.Core;
using System.Collections.Generic;

namespace RCSoft.Data
{
    public interface IDbContext
    {
        IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity;

        int SaveChanges();

        IList<TEntity> ExcuteStoredProcedureList<TEntity>(string commandText, params object[] parameters)
            where TEntity : BaseEntity, new();

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TElement">查询出来的对象</typeparam>
        /// <param name="sql">sql查询语句</param>
        /// <param name="parameters">查询语句中的参数</param>
        /// <returns></returns>
        IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters);

        /// <summary>
        /// 针对数据库执行给定的DDL/DML命令
        /// </summary>
        /// <param name="sql">sql字符串</param>
        /// <param name="timeout"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        int ExecuteSqlCommand(string sql, int? timeout = null, params object[] parameters);
    }
}
